home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Multimedia / MPC-HC / MPC-HC_Portable.exe / MPC-HC_Portable / Shaders / Edge sharpen.hlsl < prev    next >
Text File  |  2014-10-05  |  2KB  |  75 lines

  1. /*
  2.  * (C) 2003-2006 Gabest
  3.  * (C) 2006-2013 see Authors.txt
  4.  *
  5.  * This file is part of MPC-HC.
  6.  *
  7.  * MPC-HC is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 3 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * MPC-HC is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19.  *
  20.  */
  21.  
  22. sampler s0 : register(s0);
  23. float4 p0 :  register(c0);
  24.  
  25. #define width  (p0[0])
  26. #define height (p0[1])
  27.  
  28. #define NbPixel     1
  29. #define Edge_threshold  0.2
  30. #define Sharpen_val0    2.0
  31. #define Sharpen_val1    0.125
  32.  
  33. float4 main(float2 tex : TEXCOORD0) : COLOR
  34. {
  35.     // size of NbPixel pixels
  36.     float dx = NbPixel / width;
  37.     float dy = NbPixel / height;
  38.     float4 Res = 0;
  39.  
  40.     // Edge detection using Prewitt operator
  41.     // Get neighbor points
  42.     // [ 1, 2, 3 ]
  43.     // [ 4, 0, 5 ]
  44.     // [ 6, 7, 8 ]
  45.     float4 c0 = tex2D(s0, tex);
  46.     float4 c1 = tex2D(s0, tex + float2(-dx, -dy));
  47.     float4 c2 = tex2D(s0, tex + float2(  0, -dy));
  48.     float4 c3 = tex2D(s0, tex + float2( dx, -dy));
  49.     float4 c4 = tex2D(s0, tex + float2(-dx,   0));
  50.     float4 c5 = tex2D(s0, tex + float2( dx,   0));
  51.     float4 c6 = tex2D(s0, tex + float2(-dx,  dy));
  52.     float4 c7 = tex2D(s0, tex + float2(  0,  dy));
  53.     float4 c8 = tex2D(s0, tex + float2( dx,  dy));
  54.  
  55.     // Computation of the 3 derived vectors (hor, vert, diag1, diag2)
  56.     float4 delta1 = (c6 + c4 + c1 - c3 - c5 - c8);
  57.     float4 delta2 = (c4 + c1 + c2 - c5 - c8 - c7);
  58.     float4 delta3 = (c1 + c2 + c3 - c8 - c7 - c6);
  59.     float4 delta4 = (c2 + c3 + c5 - c7 - c6 - c4);
  60.  
  61.     // Computation of the Prewitt operator
  62.     float value = length(abs(delta1) + abs(delta2) + abs(delta3) + abs(delta4)) / 6;
  63.  
  64.     // If we have an edge (vector length > Edge_threshold) => apply sharpen filter
  65.     if (value > Edge_threshold) {
  66.         Res = c0 * Sharpen_val0 - (c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8) * Sharpen_val1;
  67.         // Display edges in red...
  68.         //Res = float4( 1.0, 0.0, 0.0, 0.0 );
  69.  
  70.         return Res;
  71.     } else {
  72.         return c0;
  73.     }
  74. }
  75.